// 用户相关类型
export interface User {
  id: number
  username: string
  name: string
  email: string
  role: 'admin' | 'teacher' | 'student'
  status: 'active' | 'inactive'
  created_at: string
  updated_at: string
}

// 问题相关类型
export interface Problem {
  id: number
  title: string
  description: string
  type: 'choice' | 'blank' | 'short' | 'code' | 'code_completion'
  difficulty: 'easy' | 'medium' | 'hard'
  language?: string
  answer: string
  options?: string
  points: number
  time_limit?: number
  memory_limit?: number
  test_cases?: string
  input_format?: string
  output_format?: string
  hint?: string
  solution?: string
  created_by?: number
  status: 'active' | 'inactive'
  created_at: string
  updated_at?: string
}

// 班级相关类型
export interface Class {
  id: number
  name: string
  description: string
  teacher_id: number
  max_students: number
  status: 'active' | 'inactive'
  created_at: string
  updated_at: string
  teacher?: User
  students?: User[]
  assignments?: Assignment[]
}

// 作业相关类型
export interface Assignment {
  id: number
  title: string
  description: string
  class_id: number
  problem_ids: string
  due_date: string
  total_score: number
  status: 'active' | 'inactive' | 'expired'
  created_at: string
  updated_at: string
  class?: Class
  problems?: Problem[]
  submissions?: AssignmentSubmission[]
}

// 作业提交相关类型
export interface AssignmentSubmission {
  id: number
  assignment_id: number
  student_id: number
  problem_id: number
  code?: string
  language?: string
  status: 'pending' | 'accepted' | 'rejected'
  score: number
  execution_time?: number
  memory_usage?: number
  error_message?: string
  feedback?: string
  created_at: string
  updated_at: string
  assignment?: Assignment
  student?: User
  problem?: Problem
}

// 代码评判相关类型
export interface JudgeResult {
  status: 'AC' | 'WA' | 'CE' | 'TLE' | 'MLE' | 'RE' | 'PE'
  score?: number
  max_score?: number
  execution_time?: number
  memory_usage?: number
  memory_used?: number
  error_message?: string
  message?: string
  feedback?: string
  test_cases?: TestCaseResult[]
  test_results?: TestCaseResult[]
}

export interface TestCaseResult {
  input: string
  expected_output: string
  actual_output?: string
  status: 'AC' | 'WA' | 'CE' | 'TLE' | 'MLE' | 'RE' | 'PE'
  execution_time?: number
  memory_usage?: number
  error_message?: string
}

// API请求类型
export interface LoginRequest {
  username: string
  password: string
}

export interface RegisterRequest {
  username: string
  password: string
  name: string
  email: string
  role: 'admin' | 'teacher' | 'student'
}

export interface BatchRegisterRequest {
  users: {
    username: string
    password: string
    name: string
    email: string
  }[]
}

export interface RunCodeRequest {
  problem_id: number
  code: string
  language: string
}

export interface SubmitCodeRequest {
  problem_id: number
  code: string
  language: string
}

// API响应类型
export interface ApiResponse<T = any> {
  success: boolean
  message: string
  data: T
}

export interface ProblemsResponse {
  problems: Problem[]
  total: number
  pages: number
  current_page: number
  per_page: number
}

export interface ClassesResponse {
  classes: Class[]
  total: number
  pages: number
  current_page: number
  per_page: number
}

export interface AssignmentsResponse {
  assignments: Assignment[]
  total: number
  pages: number
  current_page: number
  per_page: number
}

// 分页参数
export interface PaginationParams {
  page?: number
  per_page?: number
  search?: string
  filter?: Record<string, any>
}

// 统计数据类型
export interface ProblemStats {
  total: number
  choice: number
  blank: number
  short: number
  code: number
  code_completion: number
}

export interface ClassStats {
  total_students: number
  total_assignments: number
  active_assignments: number
  average_score: number
}

export interface AssignmentStats {
  total_submissions: number
  accepted_submissions: number
  average_score: number
  completion_rate: number
}
